package com.dss.auto_deploy.quartz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dss.auto_deploy.quartz.domain.SysJobLog;
import com.dss.auto_deploy.quartz.dto.SysJobLogPageDto;
import com.dss.auto_deploy.quartz.service.ISysJobLogService;
import com.dss.auto_deploy.util.Result;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 调度日志操作处理
 *
 * @author lenovo
 */
@RestController
@RequestMapping("/monitor/jobLog")
@Api(tags = "定时任务日志")
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
public class SysJobLogController {
    private final ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @GetMapping("/list")
    public Result list(SysJobLogPageDto sysJobLog) {
        Page<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
        return Result.success(list);
    }


    /**
     * 根据调度编号获取详细信息
     */
    @GetMapping(value = "/{jobLogId}")
    public Result getInfo(@PathVariable Long jobLogId) {
        return Result.success(jobLogService.selectJobLogById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */
    @DeleteMapping("/{jobLogIds}")
    public Result remove(@PathVariable Long[] jobLogIds) {
        return Result.success(jobLogService.deleteJobLogByIds(jobLogIds));
    }

    /**
     * 清空定时任务调度日志
     */
    @DeleteMapping("/clean")
    public Result clean() {
        jobLogService.cleanJobLog();
        return Result.success();
    }
}
